/**
 *  Copyright (c)  2011-2020 Panguso, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Panguso, 
 *  Inc. ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into with Panguso.
 */

package storage.dbhelper;

import cn.edu.thu.log.web.service.PropertiesReaderServices;
import cn.edu.thu.log.web.service.impl.PropertiesReaderServicesImpl;
import java.util.List;
import org.apache.cassandra.thrift.KeySlice;
import storage.util.StorageManager;
/**
 * 
 * @author fenyo rome
 *
 */
public class TreeFileHelper {
	/**
	 * 
	 * @param fileName
	 * fileName
	 * @param fileContent
	 * fileName
	 */
	public void saveTreeFile(String fileName, String fileContent) {
		PropertiesReaderServices x1 = PropertiesReaderServicesImpl.instance();
		StorageManager sm = new StorageManager(x1.getProperties("db_keySpace"),
				x1.getProperties("db_columnFamily_treeFile"));
		// sm.open();
		sm.setRowKey(fileName);
		sm.put("content", fileContent);

	}
	/**
	 * 
	 * @param fileName
	 * fileName
	 * @return
	 */
	public String selectTreeFile(String fileName) {
		PropertiesReaderServices x1 = PropertiesReaderServicesImpl.instance();
		StorageManager sm = new StorageManager(x1.getProperties("db_keySpace"),
				x1.getProperties("db_columnFamily_treeFile"));
		List<KeySlice> result = sm.get("key", fileName);
		String content = "";
		if (result.size() > 0) {
			KeySlice ks = result.get(0);
			content = new String(ks.getColumns().get(0).getColumn().getValue());
		}
		return content;
	}

	
}
